using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using bitzhuwei.Compiler;

namespace bitzhuwei.AnsiCFormat {
    /// <summary>
    /// Correspond to the Vn node abstract_declarator in the grammar(AnsiC).
    /// </summary>
    internal partial class Vnabstract_declarator : IFullFormatter {
        // [155]=abstract_declarator : pointer ;
        // [156]=abstract_declarator : direct_abstract_declarator ;
        // [157]=abstract_declarator : pointer direct_abstract_declarator ;

        internal Vnabstract_declarator(Vnpointer? r1, Vndirect_abstract_declarator? r0) {
            this.r1 = r1;
            this.r0 = r0;
            if (r1 != null) {
                if (r0 != null) { this._scope = new TokenRange(r1, r0); }
                else { this._scope = new TokenRange(r1); }
            }
            else {
                if (r0 != null) { this._scope = new TokenRange(r0); }
                else { throw new Exception(); }
            }
        }

        private readonly TokenRange _scope;
        private readonly Vnpointer? r1;
        private readonly Vndirect_abstract_declarator? r0;

        public TokenRange Scope => _scope;

        public void Format(TextWriter writer, FormatContext context) {
            throw new NotImplementedException();
        }

        public void FullFormat(BlankConfig preConfig, TextWriter writer, FormatContext context) {
            if (r1 != null) {
                context.PrintBlanksAnd(r1, preConfig, writer);
                if (r0 != null) {
                    var config = new BlankConfig(1, false);
                    context.PrintCommentsBetween(r1, r0, config, writer);
                    context.PrintBlanksAnd(r0, config, writer);
                }
            }
            else {
                if (r0 != null) {
                    context.PrintBlanksAnd(r0, preConfig, writer);
                }
                else { throw new Exception(); }
            }
        }

        public IEnumerable<string> YieldTokens(TextWriter writer, FormatContext context) {
            throw new NotImplementedException();
        }
    }
}
